#include "RayTracingMath.h"
#include "Render//VulkanRHI.h"
#include "Utils/FileUtil.h"
#include "Core/CoreGlobals.h"

float HaltonSequence(int base, int index)
{
	float result = 0;
	float f = 1;
	while (index > 0)
	{
		f /= base;
		result += f * (index % base);
		index = glm::floor(index / base);
	}

	return result;
}

float RadicalInverseVdc(uint32 bits)
{
	bits = (bits << 16u) | (bits >> 16u);
	bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
	bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
	bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
	bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
	return float(bits) * 2.3283064365386963e-10; // / 0x100000000
}

glm::vec2 Hammersley(uint32 i, uint32 N)
{
	return glm::vec2(float(i) / float(N), RadicalInverseVdc(i));
}
